local UIBase = require("view.UIBase")
local PopupFightEnd = class("PopupFightEnd", UIBase)

function PopupFightEnd:ctor(callback)
    self._callback = callback
    local resource = {
        path = "Prefabs/Popup",
        name = "PopupFightEnd",
        canvas = 3
    }
    PopupFightEnd.super.ctor(self, resource)
end

function PopupFightEnd:awake()
    self._listReward:SetTemplate(
        handler(self, self._onItemUpdate),
        handler(self, self._onValueChange),
        handler(self, self._onItemTouch)
    )
    self._listReward.gameObject:SetActive(false)
    self._textRewardTip.gameObject:SetActive(false)
end

function PopupFightEnd:start()
    G_UIUtil.addTouchEvent(self._panelTouch.transform, nil, nil, handler(self, self._onClickClose))
end

function PopupFightEnd:setTip(text)
    self._textTip.text = text
end

function PopupFightEnd:_onClickClose()
    self:close()
end

function PopupFightEnd:_onItemUpdate(item, index)
    local startIndex = index + 1
    local data = self._datas[startIndex]
    item:updateUI(data)
end

function PopupFightEnd:_onValueChange()
end

function PopupFightEnd:_onItemTouch()
end

function PopupFightEnd:setReward(awards)
    if #awards > 0 then
        self._listReward.gameObject:SetActive(true)
        self._textRewardTip.gameObject:SetActive(true)
        self._datas = awards
        self._listReward:ReSize(#self._datas)
    end
end

function PopupFightEnd:onClose()
    if self._callback then
        self._callback()
    end
end

return PopupFightEnd
